package com.eppear.jpfm.framework.util.datatables;

import java.util.List;

import com.eppear.jpfm.framework.constants.Constants;


/**
 * DataTables前端插件参数接收类
 * @author JianFeng Zhang(张建锋)
 * @date 2017年4月16日 上午10:41:56 
 * 
 */
public class DtParm {

	private Integer draw=null;	
	private Integer start = Constants.PAGE_DATA_START;
	private Integer length = Constants.PAGE_DATA_LENGTH;
	private Search search;
	private List<Order> order;
	private List<Columns> columns;
	private Boolean orderable = false;//是否允许后台排序 
	
	public Integer getDraw() {
		return draw;
	}
	public void setDraw(Integer draw) {
		this.draw = draw;
	}
	public Integer getStart() {
		return start;
	}
	public void setStart(Integer start) {
		if (start ==null)
			this.start = Constants.PAGE_DATA_START;
		else 
			this.start = start;
	}
	public Integer getLength() {
		return length;
	}
	public void setLength(Integer length) {
		if (length==null)
			this.length = Constants.PAGE_DATA_LENGTH;
		else 
			this.length = length;
	}
	public Search getSearch() {
		return search;
	}
	public void setSearch(Search search) {
		this.search = search;
	}
	public List<Order> getOrder() {
		return order;
	}
	public void setOrder(List<Order> order) {
		this.order = order;
	}
	public List<Columns> getColumns() {
		return columns;
	}
	public void setColumns(List<Columns> columns) {
		this.columns = columns;
	}
	public Boolean getOrderable() {
		return orderable;
	}
	public void setOrderable(Boolean orderable) {
		this.orderable = orderable;
	}
	/**
	 *   获取排序条件,SQL语句语法方式
	 * @author JianFeng Zhang(张建锋) 
	 * @data   2017-04-16 下午3:27:02
	 * @return
	 */
	public String getOrderBy(){
		String oderBy = "",dir=null,tmpstr="";
		Order odi =null;
		Integer coffset=null;
		
		for(int i =0;i<this.order.size();i++){
			if (i==0) 
				tmpstr="";
			else
				tmpstr=", ";
			odi = order.get(i);
			coffset = odi.getColumn();
			dir = odi.getDir();
			
			if ("DESC".equals(dir.trim().toUpperCase())){
				tmpstr= tmpstr + this.columns.get(coffset).getData() + " DESC";
			}else{
				tmpstr= tmpstr + this.columns.get(coffset).getData() + " ASC";
			}
			oderBy += tmpstr;
		}
		return oderBy;
	}
	
}
